package qianfeng.com.meijiadaka.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.List;

import qianfeng.com.meijiadaka.FindImageActivity;
import qianfeng.com.meijiadaka.GnkActivity;
import qianfeng.com.meijiadaka.MainActivity;
import qianfeng.com.meijiadaka.R;
import qianfeng.com.meijiadaka.TutorialActivity;
import qianfeng.com.meijiadaka.XiaoJianActivity;
import qianfeng.com.meijiadaka.bean.Home_info1;

/**
 * Created by yanshihao on 2017/2/8.
 */

public class MyListAdapter extends RecyclerView.Adapter<MyListAdapter.ViewHolder> {
    private Context mContext;
    private CallBack mCallBack;
    public interface CallBack{
        void setOnClick();
    }

    public void setCallBack(CallBack callBack) {
        mCallBack = callBack;
    }

    private List<Home_info1.ResultBean.CategoriesBean>mList;
    private RecyclerView mRecyclerView;
    public MyListAdapter(Context context, List<Home_info1.ResultBean.CategoriesBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.home_listview,parent,false);
        ViewHolder vh=new ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = mRecyclerView.getChildAdapterPosition(v);
                if (position == 0) {
                    Intent intent=new Intent(mContext, FindImageActivity.class);
                    mContext.startActivity(intent);
                }
                if (position == 1) {

                }
                if (position == 2) {
                    Intent intent=new Intent(mContext, TutorialActivity.class);
                    mContext.startActivity(intent);
                }
                if (position == 3) {
                    Intent intent=new Intent(mContext, GnkActivity.class);
                    mContext.startActivity(intent);
                }
                if (position == 4) {
                    Intent intent=new Intent(mContext, XiaoJianActivity.class);
                    mContext.startActivity(intent);
                }

            }
        });
        return vh;
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
       mRecyclerView=recyclerView;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv.setText(mList.get(position).getCategoryName());
       Glide.with(mContext).load(mList.get(position).getCategoryIcon()).into(holder.iv);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv;
        TextView tv;
        public ViewHolder(View itemView) {
            super(itemView);
            iv=(ImageView)itemView.findViewById(R.id.iv1);
            tv=(TextView)itemView.findViewById(R.id.tv1);
        }
    }
}
